﻿using System;
using System.Collections.Generic;
using System.Linq;
using NHibernate;
using NHibernate.Linq;
using Hasiu.Entity;

namespace Hasiu.Service
{
    public class SlideService
    {
        public static readonly SlideService _ = new SlideService();

        private ISession Session { get; set; }

        public SlideService()
        {
            Session = NHibernateHelper.GetCurrentSession();
        }

        public void Save(Slide slide)
        {
            Session.Save(slide);
            Session.Flush();
        }

        public void Delete(params String[] id)
        {
            var query = Session.Query<Slide>().Where(p => id.Contains(p.Id));
            foreach (var v in query)
            {
                Session.Delete(v);
            }
            Session.Flush();
        }

        public void Update(Slide slide)
        {
            Session.Update(slide);
            Session.Flush();
        }

        public Slide Get(string id)
        {
            return Session.Get<Slide>(id);
        }

        public IList<Slide> GetList()
        {
            return Session.Query<Slide>().ToList();
        }
    }
}
